/*
 * @Author: 徐建辰
 * @Date: 2022-02-12 14:17:50
 * @LastEditTime: 2022-02-12 16:23:44
 * @LastEditors: 徐建辰
 * @Description: 路由表处理
 */
import {isArray} from './type'

/**
 * @description: 根据路由表配置生成tabbar菜单
 * @param {*Array} routes 当前路由表
 * @return {*Array} 
 */
export function generateTabbar(routes) {
  if (!isArray(routes)) return
  let tabbars = []
  routes.map(route => {
    if (route.meta && route.meta.tabbar) {
      tabbars.push(route)
    }
  })

  return tabbars
}

// 过滤出只含有路径的tabbar白名单
export function filterTabbar(routes, isAddLogin = false) {
  if (!isArray(routes)) return
  let whitelist = isAddLogin ? [...routes.map(r => r.path), '/login'] : routes.map(r => r.path)
  return whitelist
}